package com.acme.bankapp.domain.bank.accounts;

import com.acme.bankapp.domain.bank.exceptions.NotEnoughFundsException;
import com.acme.bankapp.domain.bank.exceptions.OverdraftLimitExcededException;


@SuppressWarnings("serial")
public class CheckingAccount extends AbstractAccount {
	protected double overdraft;
	
	public CheckingAccount(double initialBalance, double overdraft) {
		super(initialBalance);
		if (overdraft < 0) throw new IllegalArgumentException();
		this.overdraft = overdraft;
	}
	
	@Override
	public void withdraw(double x) throws NotEnoughFundsException {
		if (x <= balance + overdraft) {
			balance -= x;
		} else {
			throw new OverdraftLimitExcededException (x - balance);
		}
	}

	public double maximalAmountToWithdraw() {
		return balance + overdraft;
	}
}
